/*
 * DemoFuzzyLogicView.java
 */
package com.fuzzylogic;

import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;

import com.system.Constants;
import com.utility.Utility;
import javax.swing.JOptionPane;

/**
 * The application's main frame.
 */
public class DemoFuzzyLogicView extends FrameView {

    //kếp quả thành phần huyết áp    
    double result_hp[]; // = new double[11];
    //kết quả thành phần nhịp tim
    double result_nt[] = new double[7];
    //Mảng T, N
    ArrayList<MapValue> arr_map_t = new ArrayList<MapValue>();
    ArrayList<MapValue> arr_map_n = new ArrayList<MapValue>();
    ArrayList<MapValue> arr_pp_map = new ArrayList<MapValue>();
    ArrayList<MapValue> arr_ao = new ArrayList<MapValue>();
    ArrayList<MapValue> arr_tb = new ArrayList<MapValue>();

    public DemoFuzzyLogicView(SingleFrameApplication app) {
        super(app);

        initComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String) (evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer) (evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
        //set focus
        txtHuyetAp.requestFocus();
    }

    /**
     * Kết quả chuẩn đoán
     */
    @Action
    public void displayResult() {

        //check giá trị nhập vào
        boolean input = Utility.checkInt(txtHuyetAp.getText(), txtNhipTim.getText());

        if (input) {
            //check giá trị max huyết ap & nhịp tim
            boolean chk_max = Utility.CheckMax(txtHuyetAp.getText(), txtNhipTim.getText());
            if (chk_max) {
                result_hp = new double[11];
                result_nt = new double[7];
                arr_map_t.clear();
                arr_map_n.clear();
                arr_pp_map.clear();
                arr_ao.clear();
                //Check Huyết áp
                chkHUYET_AP();
                //Check Nhịp tim
                chkNHIP_TIM();
                //tìm kiếm TN
                searchTN();
                //set focus
                txtHuyetAp.requestFocus();
            } else {
                JOptionPane.showMessageDialog(null, "Huyết ap " + txtHuyetAp.getText() + " hoặc nhịp tim " + txtNhipTim.getText() + " không nằm trong khoảng cho phép.", "Kiểm tra lại thông tin", JOptionPane.INFORMATION_MESSAGE);
                txtHuyetAp.requestFocus();
                lblHAp.setText("Thành phần huyết áp: ");
                //Thành phần N được sử dụng
                lblNtim.setText("Thành phần nhịp tim: ");
                //kết quả liều dùng
                lblResult.setText("Kết quả: ");
            }
        } else {
            JOptionPane.showMessageDialog(null, "Huyết ap " + txtHuyetAp.getText() + " hoặc nhịp tim " + txtNhipTim.getText() + " không đúng.", "Kiểm tra lại thông tin", JOptionPane.INFORMATION_MESSAGE);
            txtHuyetAp.requestFocus();
            lblHAp.setText("Thành phần huyết áp: ");
            //Thành phần N được sử dụng
            lblNtim.setText("Thành phần nhịp tim: ");
            //kết quả liều dùng
            lblResult.setText("Kết quả: ");
        }
    }

    /**
     * Kiểm tra huyết áp thuộc thành phần nào
     */
    public void chkHUYET_AP() {

        int value = Integer.parseInt(txtHuyetAp.getText());

        if ((Constants.HUYET_AP_T1[0] <= value) && (value < Constants.HUYET_AP_T1[3])) {
            result_hp[0] = Utility.resultThanhPhan(Constants.HUYET_AP_T1, value);
        }

        if ((Constants.HUYET_AP_T2[0] <= value) && (value < Constants.HUYET_AP_T2[3])) {
            result_hp[1] = Utility.resultThanhPhan(Constants.HUYET_AP_T2, value);
        }

        if ((Constants.HUYET_AP_T3[0] <= value) && (value < Constants.HUYET_AP_T3[3])) {
            result_hp[2] = Utility.resultThanhPhan(Constants.HUYET_AP_T3, value);
        }

        if ((Constants.HUYET_AP_T4[0] <= value) && (value < Constants.HUYET_AP_T4[3])) {
            result_hp[3] = Utility.resultThanhPhan(Constants.HUYET_AP_T4, value);
        }

        if ((Constants.HUYET_AP_T5[0] <= value) && (value < Constants.HUYET_AP_T5[3])) {
            result_hp[4] = Utility.resultThanhPhan(Constants.HUYET_AP_T5, value);
        }

        if ((Constants.HUYET_AP_T6[0] <= value) && (value < Constants.HUYET_AP_T6[3])) {
            result_hp[5] = Utility.resultThanhPhan(Constants.HUYET_AP_T6, value);
        }

        if ((Constants.HUYET_AP_T7[0] <= value) && (value < Constants.HUYET_AP_T7[3])) {
            result_hp[6] = Utility.resultThanhPhan(Constants.HUYET_AP_T7, value);
        }

        if ((Constants.HUYET_AP_T8[0] <= value) && (value < Constants.HUYET_AP_T8[3])) {
            result_hp[7] = Utility.resultThanhPhan(Constants.HUYET_AP_T8, value);
        }

        if ((Constants.HUYET_AP_T9[0] <= value) && (value < Constants.HUYET_AP_T9[3])) {
            result_hp[8] = Utility.resultThanhPhan(Constants.HUYET_AP_T9, value);
        }

        if ((Constants.HUYET_AP_T10[0] <= value) && (value < Constants.HUYET_AP_T10[3])) {
            result_hp[9] = Utility.resultThanhPhan(Constants.HUYET_AP_T10, value);
        }

        if ((Constants.HUYET_AP_T11[0] <= value) && (value < Constants.HUYET_AP_T11[3])) {
            result_hp[10] = Utility.resultThanhPhan(Constants.HUYET_AP_T11, value);
        }

    }

    /**
     * Kiểm tra nhịp tim thuộc thành phần nào
     */
    public void chkNHIP_TIM() {

        int value = Integer.parseInt(txtNhipTim.getText());

        if ((Constants.NHIP_TIM_T1[0] <= value) && (value < Constants.NHIP_TIM_T1[3])) {
            result_nt[0] = Utility.resultThanhPhan(Constants.NHIP_TIM_T1, value);
        }

        if ((Constants.NHIP_TIM_T2[0] <= value) && (value < Constants.NHIP_TIM_T2[3])) {
            result_nt[1] = Utility.resultThanhPhan(Constants.NHIP_TIM_T2, value);
        }

        if ((Constants.NHIP_TIM_T3[0] <= value) && (value < Constants.NHIP_TIM_T3[3])) {
            result_nt[2] = Utility.resultThanhPhan(Constants.NHIP_TIM_T3, value);
        }

        if ((Constants.NHIP_TIM_T4[0] <= value) && (value < Constants.NHIP_TIM_T4[3])) {
            result_nt[3] = Utility.resultThanhPhan(Constants.NHIP_TIM_T4, value);
        }

        if ((Constants.NHIP_TIM_T5[0] <= value) && (value < Constants.NHIP_TIM_T5[3])) {
            result_nt[4] = Utility.resultThanhPhan(Constants.NHIP_TIM_T5, value);
        }

        if ((Constants.NHIP_TIM_T6[0] <= value) && (value < Constants.NHIP_TIM_T6[3])) {
            result_nt[5] = Utility.resultThanhPhan(Constants.NHIP_TIM_T6, value);
        }

        if ((Constants.NHIP_TIM_T7[0] <= value) && (value < Constants.NHIP_TIM_T7[3])) {
            result_nt[6] = Utility.resultThanhPhan(Constants.NHIP_TIM_T7, value);
        }


    }

    /**
     * Quy tắc cho đầu vào T, N -> A 
     */
    public void searchTN() {

        StringBuffer pp_logic = new StringBuffer();
        StringBuffer tp_t = new StringBuffer();
        StringBuffer tp_n = new StringBuffer();

        pp_logic.append("[ ");
        tp_t.append("[ ");
        tp_n.append("[ ");
        for (int i = 0; i < result_hp.length; i++) {
            //Check tồn tại thành phần T
            if (result_hp[i] > 0) {
                //map key value
                MapValue map = new MapValue();
                map.setKey(Constants.NAME_THANH_PHAN_HUYET_AP[i]);
                map.setValue(result_hp[i]);
                arr_map_t.add(map);
                tp_t.append(Constants.NAME_THANH_PHAN_HUYET_AP[i]);
                tp_t.append(" ");
            }
        }

        for (int i = 0; i < result_nt.length; i++) {
            //Check tồn tại thành phần T
            if (result_nt[i] > 0) {
                //map key value
                MapValue map = new MapValue();
                map.setKey(Constants.NAME_THANH_PHAN_NHIP_TIM[i]);
                map.setValue(result_nt[i]);
                arr_map_n.add(map);
                tp_n.append(Constants.NAME_THANH_PHAN_NHIP_TIM[i]);
                tp_n.append(" ");
            }
        }

        tp_t.append("]");
        tp_n.append("]");

        //Kiểm tra xem liều lượng thuốc sử dụng cho bệnh nhân
        if (arr_map_n.size() > 0 && arr_map_t.size() > 0) {
            //Từ T và N -> A ..
            for (int i = 0; i < arr_map_n.size(); i++) {
                for (int t = 0; t < arr_map_t.size(); t++) {
                    //set key & value
                    MapValue mv = new MapValue();
                    mv.setKey(arr_map_t.get(t).getKey() + arr_map_n.get(i).getKey());
                    mv.setValue(Utility.setMin(arr_map_t.get(t).getValue(), arr_map_n.get(i).getValue()));
                    arr_pp_map.add(mv);
                }
            }

            for (int l = 0; l < arr_pp_map.size(); l++) {

                for (int z = 0; z < Constants.Col.length; z++) {
                    //set giá trị T& N trong bảng logic
                    if (arr_pp_map.get(l).getKey().equals(Constants.Col[z])) {
                        MapValue mv = new MapValue();
                        mv.setKey(Constants.Val[z]);
                        mv.setValue(arr_pp_map.get(l).getValue());
                        arr_ao.add(mv);

                        pp_logic.append(Constants.Val[z]);
                        pp_logic.append(" ");
                    }
                }
            }

            //Tìm Y của A1 -> A5            
            double tb_a1 = 0, tb_a2 = 0, tb_a3 = 0, tb_a4 = 0, tb_a5 = 0, tb_a1_ = 0, tb_a2_ = 0, tb_a3_ = 0, tb_a4_ = 0, tb_a5_ = 0;

            for (int a = 0; a < arr_ao.size(); a++) {
                double x_truoc = 0, x_sau = 0;
                String key_temp_a1 = "", key_temp_a2 = "", key_temp_a3 = "", key_temp_a4 = "", key_temp_a5 = "";
                //Tính Trung bình A1                
                if (arr_ao.get(a).getKey().equals("A1") && key_temp_a1.isEmpty()) {
                    x_truoc = 0;
                    if (arr_ao.get(a).getValue() >= 0.5) {
                        x_sau = Constants.DIEMCUOI_A1 + (1 - arr_ao.get(a).getValue()) * 0.5;
                    } else {
                        x_sau = Constants.DIEMCUOI_A1 + arr_ao.get(a).getValue() * 0.5;
                    }
                    tb_a1 = (x_truoc + x_sau) / 2;
                    key_temp_a1 = "A1";
                }
                if (arr_ao.get(a).getKey().equals("A1") && key_temp_a1.equals("A1")) {
                    x_truoc = 0;
                    if (arr_ao.get(a).getValue() >= 0.5) {
                        x_sau = Constants.DIEMCUOI_A1 + (1 - arr_ao.get(a).getValue()) * 0.5;
                    } else {
                        x_sau = Constants.DIEMCUOI_A1 + arr_ao.get(a).getValue() * 0.5;
                    }
                    tb_a1_ = (x_truoc + x_sau) / 2;
                }
                //Tính Trung bình A2
                if (arr_ao.get(a).getKey().equals("A2") && key_temp_a2.isEmpty()) {
                    x_truoc = Constants.DIEMCUOI_A1 + arr_ao.get(a).getValue() * 0.5;
                    if (arr_ao.get(a).getValue() >= 0.5) {
                        x_sau = Constants.DIEMCUOI_A2 + (1 - arr_ao.get(a).getValue()) * 0.2;
                    } else {
                        x_sau = Constants.DIEMCUOI_A2 + arr_ao.get(a).getValue() * 0.2;
                    }
                    tb_a2 = (x_truoc + x_sau) / 2;
                    key_temp_a2 = "A2";
                }
                if (arr_ao.get(a).getKey().equals("A2") && key_temp_a2.equals("A2")) {
                    x_truoc = Constants.DIEMCUOI_A1 + arr_ao.get(a).getValue() * 0.5;
                    if (arr_ao.get(a).getValue() >= 0.5) {
                        x_sau = Constants.DIEMCUOI_A2 + (1 - arr_ao.get(a).getValue()) * 0.2;
                    } else {
                        x_sau = Constants.DIEMCUOI_A2 + arr_ao.get(a).getValue() * 0.2;
                    }
                    tb_a2_ = (x_truoc + x_sau) / 2;
                }

                //Tính Trung bình A3
                if (arr_ao.get(a).getKey().equals("A3") && key_temp_a3.isEmpty()) {
                    x_truoc = Constants.DIEMCUOI_A2 + arr_ao.get(a).getValue() * 0.2;
                    if (arr_ao.get(a).getValue() >= 0.5) {
                        x_sau = Constants.DIEMCUOI_A3 + (1 - arr_ao.get(a).getValue()) * 0.5;
                    } else {
                        x_sau = Constants.DIEMCUOI_A3 + arr_ao.get(a).getValue() * 0.5;
                    }
                    tb_a3 = (x_truoc + x_sau) / 2;
                    key_temp_a3 = "A3";
                }
                if (arr_ao.get(a).getKey().equals("A3") && key_temp_a3.equals("A3")) {
                    x_truoc = Constants.DIEMCUOI_A2 + arr_ao.get(a).getValue() * 0.2;
                    if (arr_ao.get(a).getValue() >= 0.5) {
                        x_sau = Constants.DIEMCUOI_A3 + (1 - arr_ao.get(a).getValue()) * 0.5;
                    } else {
                        x_sau = Constants.DIEMCUOI_A3 + arr_ao.get(a).getValue() * 0.5;
                    }
                    tb_a3_ = (x_truoc + x_sau) / 2;
                }
                //Tính Trung bình A4                

                if (arr_ao.get(a).getKey().equals("A4") && key_temp_a4.isEmpty()) {
                    x_truoc = Constants.DIEMCUOI_A3 + arr_ao.get(a).getValue() * 0.5;
                    if (arr_ao.get(a).getValue() >= 0.5) {
                        x_sau = Constants.DIEMCUOI_A4 + (1 - arr_ao.get(a).getValue()) * 0.5;
                    } else {
                        x_sau = Constants.DIEMCUOI_A4 + arr_ao.get(a).getValue() * 0.5;
                    }
                    tb_a4 = (x_truoc + x_sau) / 2;
                    key_temp_a4 = "A4";
                }
                if (arr_ao.get(a).getKey().equals("A4") && key_temp_a4.equals("A4")) {
                    x_truoc = Constants.DIEMCUOI_A3 + arr_ao.get(a).getValue() * 0.5;
                    if (arr_ao.get(a).getValue() >= 0.5) {
                        x_sau = Constants.DIEMCUOI_A4 + (1 - arr_ao.get(a).getValue()) * 0.5;
                    } else {
                        x_sau = Constants.DIEMCUOI_A4 + arr_ao.get(a).getValue() * 0.5;
                    }
                    tb_a4_ = (x_truoc + x_sau) / 2;
                }
                //Tính Trung bình A5
                if (arr_ao.get(a).getKey().equals("A5") && key_temp_a5.isEmpty()) {
                    x_truoc = Constants.DIEMCUOI_A4 + arr_ao.get(a).getValue() * 0.5;
                    x_sau = 4;
                    tb_a5 = (x_truoc + x_sau) / 2;
                    key_temp_a5 = "A5";
                }
                if (arr_ao.get(a).getKey().equals("A5") && key_temp_a5.equals("A5")) {
                    x_truoc = Constants.DIEMCUOI_A4 + arr_ao.get(a).getValue() * 0.5;
                    x_sau = 4;
                    tb_a5_ = (x_truoc + x_sau) / 2;
                }

            }
            //Tinh MA1, MA2, MA3, MA4, MA5
            double MA1 = 0, MA2 = 0, MA3 = 0, MA4 = 0, MA5 = 0, MA1_ = 0, MA2_ = 0, MA3_ = 0, MA4_ = 0, MA5_ = 0;

            if (tb_a1 > 0) {
                MA1 = (0.5 - tb_a1) / 0.5;
            }
            if ((Constants.THANHPHAN_A2[0] <= tb_a2) && (tb_a2 < Constants.THANHPHAN_A2[3])) {
                MA2 = Utility.resultThanhPhan(Constants.THANHPHAN_A2, tb_a2);
            }
            if ((Constants.THANHPHAN_A3[0] <= tb_a3) && (tb_a3 < Constants.THANHPHAN_A3[3])) {
                MA3 = Utility.resultThanhPhan(Constants.THANHPHAN_A3, tb_a3);
            }
            if ((Constants.THANHPHAN_A4[0] <= tb_a4) && (tb_a4 < Constants.THANHPHAN_A4[3])) {
                MA4 = Utility.resultThanhPhan(Constants.THANHPHAN_A4, tb_a4);
            }
            if (tb_a5 > 0) {
                MA5 = (3.5 - tb_a5) / -0.5;
            }

            if (tb_a1_ > 0) {
                MA1_ = (0.5 - tb_a1_) / 0.5;
            }
            if ((Constants.THANHPHAN_A2[0] <= tb_a2_) && (tb_a2_ < Constants.THANHPHAN_A2[3])) {
                MA2_ = Utility.resultThanhPhan(Constants.THANHPHAN_A2, tb_a2_);
            }
            if ((Constants.THANHPHAN_A3[0] <= tb_a3_) && (tb_a3_ < Constants.THANHPHAN_A3[3])) {
                MA3_ = Utility.resultThanhPhan(Constants.THANHPHAN_A3, tb_a3_);
            }
            if ((Constants.THANHPHAN_A4[0] <= tb_a4_) && (tb_a4_ < Constants.THANHPHAN_A4[3])) {
                MA4_ = Utility.resultThanhPhan(Constants.THANHPHAN_A4, tb_a4_);
            }
            if (tb_a5_ > 0) {
                MA5_ = (3.5 - tb_a5_) / -0.5;
            }

            double Ao = ((tb_a1 * MA1) + (tb_a2 * MA2) + (tb_a3 * MA3) + (tb_a4 * MA4) + (tb_a5 * MA5)
                    + (tb_a1_ * MA1_) + (tb_a2_ * MA2_) + (tb_a3_ * MA3_) + (tb_a4_ * MA4_) + (tb_a5_ * MA5_))
                    / (MA1 + MA2 + MA3 + MA4 + MA5 + MA1_ + MA2_ + MA3_ + MA4_ + MA5_);
            
                        
            pp_logic.append("]");

            //Thành phần T được sử dụng
            lblHAp.setText("Thành phần huyết áp: " + tp_t.toString());
            //Thành phần N được sử dụng
            lblNtim.setText("Thành phần nhịp tim: " + tp_n.toString());
            //hiển thị các phương pháp suy luận            
            lblPPLogic.setText("Các phương pháp suy luận mờ được sử dụng: " + pp_logic.toString());          
            String result = "Bệnh nhân này cần " + Ao + "% để gây mê.";
            //kết quả liều dùng
            if ((pp_logic.toString().replace("]", "").replace("[", "").trim().indexOf("A")) >= 0) {
                lblResult.setText(result.replaceAll("NaN", "0"));
            } else {
                lblResult.setText("Không thể gây mê cho bệnh nhân này");
            }
        } else {
            lblHAp.setText("Thành phần huyết áp: " + tp_t.toString());
            //Thành phần N được sử dụng
            lblNtim.setText("Thành phần nhịp tim: " + tp_n.toString());
            //kết quả liều dùng
            lblResult.setText("Hiện tại không còn liều cho bệnh nhân này!");
        }

    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = DemoFuzzyLogicApp.getApplication().getMainFrame();
            aboutBox = new DemoFuzzyLogicAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        DemoFuzzyLogicApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        btnKetQua = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtHuyetAp = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtNhipTim = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        lblHAp = new javax.swing.JLabel();
        lblResult = new javax.swing.JLabel();
        lblNtim = new javax.swing.JLabel();
        lblPPLogic = new javax.swing.JLabel();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();

        mainPanel.setName("mainPanel"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(com.fuzzylogic.DemoFuzzyLogicApp.class).getContext().getActionMap(DemoFuzzyLogicView.class, this);
        btnKetQua.setAction(actionMap.get("displayResult")); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(com.fuzzylogic.DemoFuzzyLogicApp.class).getContext().getResourceMap(DemoFuzzyLogicView.class);
        btnKetQua.setText(resourceMap.getString("btnKetQua.text")); // NOI18N
        btnKetQua.setName("btnKetQua"); // NOI18N

        jButton2.setAction(actionMap.get("quit")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel1.border.title"))); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        txtHuyetAp.setText(resourceMap.getString("txtHuyetAp.text")); // NOI18N
        txtHuyetAp.setName("txtHuyetAp"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        txtNhipTim.setText(resourceMap.getString("txtNhipTim.text")); // NOI18N
        txtNhipTim.setName("txtNhipTim"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtHuyetAp)
                    .addComponent(txtNhipTim, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(13, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1)
                    .addComponent(txtHuyetAp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2)
                    .addComponent(txtNhipTim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel2.border.title"))); // NOI18N
        jPanel2.setName("jPanel2"); // NOI18N

        lblHAp.setFont(resourceMap.getFont("lblHAp.font")); // NOI18N
        lblHAp.setForeground(resourceMap.getColor("lblHAp.foreground")); // NOI18N
        lblHAp.setText(resourceMap.getString("lblHAp.text")); // NOI18N
        lblHAp.setName("lblHAp"); // NOI18N

        lblResult.setFont(resourceMap.getFont("lblResult.font")); // NOI18N
        lblResult.setForeground(resourceMap.getColor("lblResult.foreground")); // NOI18N
        lblResult.setText(resourceMap.getString("lblResult.text")); // NOI18N
        lblResult.setName("lblResult"); // NOI18N

        lblNtim.setFont(resourceMap.getFont("lblNtim.font")); // NOI18N
        lblNtim.setForeground(resourceMap.getColor("lblNtim.foreground")); // NOI18N
        lblNtim.setText(resourceMap.getString("lblNtim.text")); // NOI18N
        lblNtim.setName("lblNtim"); // NOI18N

        lblPPLogic.setFont(resourceMap.getFont("lblPPLogic.font")); // NOI18N
        lblPPLogic.setForeground(resourceMap.getColor("lblPPLogic.foreground")); // NOI18N
        lblPPLogic.setText(resourceMap.getString("lblPPLogic.text")); // NOI18N
        lblPPLogic.setName("lblPPLogic"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblNtim, javax.swing.GroupLayout.DEFAULT_SIZE, 366, Short.MAX_VALUE)
                    .addComponent(lblHAp, javax.swing.GroupLayout.DEFAULT_SIZE, 366, Short.MAX_VALUE)
                    .addComponent(lblPPLogic, javax.swing.GroupLayout.DEFAULT_SIZE, 366, Short.MAX_VALUE)
                    .addComponent(lblResult, javax.swing.GroupLayout.DEFAULT_SIZE, 366, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblHAp, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblNtim, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblPPLogic, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblResult, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(18, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGap(86, 86, 86)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(110, 110, 110)
                        .addComponent(btnKetQua, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(138, 138, 138))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton2, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnKetQua, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGap(18, 18, 18)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(69, Short.MAX_VALUE))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 622, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 452, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnKetQua;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JLabel lblHAp;
    private javax.swing.JLabel lblNtim;
    private javax.swing.JLabel lblPPLogic;
    private javax.swing.JLabel lblResult;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JTextField txtHuyetAp;
    private javax.swing.JTextField txtNhipTim;
    // End of variables declaration//GEN-END:variables
    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;
    private JDialog aboutBox;
}
